#!/usr/bin/env python
# -*- coding: utf-8 -*-
import base64
from collections import namedtuple
from collections import defaultdict
from collections import Counter


def point1():
    Point = namedtuple('Point', ['x', 'y'])  # 具备tuple的不变性，又可以根据属性来引用，使用十分方便。
    p = Point(1, 2)
    print p.x


def circle1():
    # namedtuple('名称', [属性list]):
    Circle = namedtuple('Circle', ['x', 'y', 'r'])
    circle = Circle(3, 5, 9)
    print circle.x, circle.y, circle.r


def defaultdic1():
    dd = defaultdict(lambda: 'N/A')
    dd['key1'] = 'abc'
    print dd['key1']  # key1存在
    print dd['key2']  # key2不存在，返回默认值


def counter01():
    c = Counter()  # 统计字符出现的个数：
    for ch in 'programming':
        c[ch] = c[ch] + 1
    print c


def base64_():  # base64是一种编码方法
    print base64.b64encode('hello world')
    print base64.b64decode('aGVsbG8gd29ybGQ=')


if __name__ == '__main__':
    point1()
    circle1()
    defaultdic1()
    counter01()
    base64_()
